package ru.hh.team02.chat.database;

import ru.hh.team02.chat.messaging.Message;
import ru.hh.team02.chat.messaging.PrivateMessage;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DbStub implements DatabaseServiceInterface {
    private Map<String, String> roomByClientName = new HashMap<String, String>();

    public DbStub() {
    }

    /**
     * Generate database filled with data.
     * @param data Array of data, each item of which is an array
     *             in the following format: [Client name, Room name]
     */
    public DbStub(String [][] data) {
        for (String [] item: data) {
            roomByClientName.put(item[0], item[1]);
        }
    }

    @Override
    public boolean clientExists(String name) {
        return false;
    }

    @Override
    public String getPasswordByClientName(String name) {
        return null;
    }

    @Override
    public String getRoomNameByClientName(String name) {
        return roomByClientName.get(name);
    }

    @Override
    public int putNewPersonalMessageIntoDatabase(String message, String recipientName) {
        return 0;
    }

    @Override
    public boolean markPersonalMessageAsDelivered(int id) {
        return false;
    }

    @Override
    public List<Message> getAllUndeliveredMessagesToTheClient(String clientName) {
        return Collections.emptyList();
    }

    @Override
    public PrivateMessage getMessagesById(int id) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String[] getAllRooms() {
        return new String[0];
    }


    @Override
    public void changeRoom(String clientName, String room) {
        if (!roomByClientName.containsKey(clientName)) {
            return;
        }
        roomByClientName.put(clientName, room);
    }
}
